package com.dongnam.quanly.web.nghiepvu.muabanhang.doisoat;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.SessionScoped;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.dongnam.quanly.common.controller.ChiTietDonHangController;
import com.dongnam.quanly.common.controller.ChiTietHoaDonController;
import com.dongnam.quanly.common.controller.ChiTietPhieuNhapXuatController;
import com.dongnam.quanly.common.controller.DonHangController;
import com.dongnam.quanly.common.controller.HoaDonController;
import com.dongnam.quanly.common.controller.PhieuNhapXuatController;
import com.dongnam.quanly.common.model.ChiTietDonHang;
import com.dongnam.quanly.common.model.ChiTietHoaDon;
import com.dongnam.quanly.common.model.ChiTietPhieuNhapXuat;
import com.dongnam.quanly.common.model.DonHang;
import com.dongnam.quanly.web.UserBean;

@ManagedBean(name = "DoiSoatBean")
@SessionScoped
public class DoiSoatBean implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private static final Logger logger = LoggerFactory.getLogger(DoiSoatBean.class);
	@ManagedProperty(value = "#{UserBean}")
	private UserBean userBean;
	private DonHang DonHang;
	// load DonHang
	private DonHangController DonHangController;
	private List<DonHang> listDonHang;
	// ChiTietDonHang
	private List<ChiTietDonHang> chiTietDonHangs;
	private ChiTietDonHangController chitietdonhangController;
	// ChiTietHoaDon
	private List<Object[]> chiTietHoaDons;
	private ChiTietHoaDonController chiTietHoaDonController;
	// ChiTietPhieuNhapXuat
	private List<Object[]> chiTietPhieuNhapXuats;
	private ChiTietPhieuNhapXuatController chiTietPhieuNhapXuatController;
	// HoaDon
	private List<String> soHoaDon;
	private HoaDonController hoaDonController;
	// PhieuNhapXuat
	private List<String> soPNX;
	private PhieuNhapXuatController phieuNhapXuatController;
	private String soChungTu;
	private DonHang donHangTimThay;

	// Hoa Don
	// private HoaDon HoaDonTimThay;
	// private HoaDonController hoaDonController;
	public DoiSoatBean() {
		findListDonHang();
	}

	public void timKiemDonHang() {
		chiTietDonHangs = new ArrayList<ChiTietDonHang>();
		chiTietDonHangs = getChiTietDonHangController().getListCtdh(soChungTu);
		// chiTietHoaDons = new ArrayList<ChiTietHoaDon>();
		chiTietHoaDons = new ArrayList<Object[]>();
		chiTietHoaDons = getChiTietHoaDonController().getListCthd(soChungTu);

		chiTietPhieuNhapXuats = new ArrayList<Object[]>();
		chiTietPhieuNhapXuats = getChiTietPhieuNhapXuatController().getChiTietPhieuNhapXuatByDonHang(soChungTu);
		soHoaDon = new ArrayList<String>();
		soHoaDon = getHoaDonController().getListHoaDon(soChungTu);
		soPNX = new ArrayList<String>();
		soPNX = getPhieuNhapXuatController().getListPNX(soChungTu);
	}

	public List<DonHang> findListDonHang() {
		listDonHang = getDonHangController().findAll("updateDate", "DESCENDING");
		return listDonHang;
	}

	public ChiTietDonHangController getChiTietDonHangController() {
		if (chitietdonhangController == null)
			chitietdonhangController = new ChiTietDonHangController();
		return chitietdonhangController;
	}

	public DonHangController getDonHangController() {
		if (DonHangController == null)
			DonHangController = new DonHangController();
		return DonHangController;
	}

	public ChiTietHoaDonController getChiTietHoaDonController() {
		if (chiTietHoaDonController == null)
			chiTietHoaDonController = new ChiTietHoaDonController();
		return chiTietHoaDonController;
	}

	public PhieuNhapXuatController getPhieuNhapXuatController() {
		if (phieuNhapXuatController == null)
			phieuNhapXuatController = new PhieuNhapXuatController();
		return phieuNhapXuatController;
	}

	public HoaDonController getHoaDonController() {
		if (hoaDonController == null)
			hoaDonController = new HoaDonController();
		return hoaDonController;
	}

	public ChiTietPhieuNhapXuatController getChiTietPhieuNhapXuatController() {
		if (chiTietPhieuNhapXuatController == null)
			chiTietPhieuNhapXuatController = new ChiTietPhieuNhapXuatController();
		return chiTietPhieuNhapXuatController;
	}

	public UserBean getUserBean() {
		return userBean;
	}

	public void setUserBean(UserBean userBean) {
		this.userBean = userBean;
	}

	public DonHang getDonHang() {
		return DonHang;
	}

	public void setDonHang(DonHang DonHang) {
		this.DonHang = DonHang;
	}

	public String getSoChungTu() {
		return soChungTu;
	}

	public void setSoChungTu(String soChungTu) {
		this.soChungTu = soChungTu;
	}

	public List<DonHang> getListDonHang() {
		return listDonHang;
	}

	public void setDonHangController(DonHangController DonHangController) {
		this.DonHangController = DonHangController;
	}

	public DonHang getDonHangTimThay() {
		return donHangTimThay;
	}

	public void setDonHangTimThay(DonHang donHangTimThay) {
		this.donHangTimThay = donHangTimThay;
	}

	public List<ChiTietDonHang> getChiTietDonHangs() {
		return chiTietDonHangs;
	}

	public void setChiTietDonHangs(List<ChiTietDonHang> chiTietDonHangs) {
		this.chiTietDonHangs = chiTietDonHangs;
	}

	public ChiTietDonHangController getChitietdonhangController() {
		return chitietdonhangController;
	}

	public void setChitietdonhangController(ChiTietDonHangController chitietdonhangController) {
		this.chitietdonhangController = chitietdonhangController;
	}

	public List<Object[]> getChiTietHoaDons() {
		return chiTietHoaDons;
	}

	public List<Object[]> getChiTietPhieuNhapXuats() {
		return chiTietPhieuNhapXuats;
	}

	public List<String> getSoHoaDon() {
		return soHoaDon;
	}

	public List<String> getSoPNX() {
		return soPNX;
	}

}
